$(document).ready( function() {                      
    $('#bodycolor').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#bodycolor').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });                      
                     
    $('#main_text_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#main_text_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#main_link_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#main_link_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#content_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#content_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#content_text_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#content_text_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#content_link_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#content_link_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#tab_bakground_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#tab_bakground_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#tab_border_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#tab_border_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#tab_text_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#tab_text_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });  
    
    $('#tab_current_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#tab_current_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });
    
    $('#sidebar_border_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#sidebar_border_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });
    
    $('#sidebar_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#sidebar_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });
    
    $('#sidebar_text_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#sidebar_text_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });
    
    $('#sidebar_link_color').ColorPicker({
        onShow: function (colpkr) {
            $(colpkr).fadeIn(500);
            return false;
        },
        onHide: function (colpkr) {
            $(colpkr).fadeOut(500);
            return false;
        },
        onSubmit: function(hsb, hex, rgb) {
            $('#sidebar_link_color').val('#'+hex);                                
        },
        onBeforeShow: function () {
            $(this).ColorPickerSetColor(this.value);
        }
    })
    .bind('keyup', function(){
        $(this).ColorPickerSetColor(this.value);
    });
    
    //Set disable for background image    
    function status_backgroundbox() {
        var type_index = $('#body_type').val();                                 
        if (type_index < 2) {
            $('#header_image').attr('disabled','disabled');
            $('#footer_image').attr('disabled','disabled');
            if (type_index < 1)
                $('#bodyimage').attr('disabled','disabled');
            else
                $('#bodyimage').removeAttr('disabled');                             
        }    
        else {
            $('#bodyimage').attr('disabled','disabled');
            $('#header_image').removeAttr('disabled');
            $('#footer_image').removeAttr('disabled');
        }      
    }
    $('#body_type').change(function() {                            
        status_backgroundbox();                   
    }); 
    //Update background image box first load
    status_backgroundbox();                  
    
    $('.plus_minus_theme').hover(function(){ $(this).css('cursor','pointer'); },
        function() { $(this).css('cursor','default'); }
    );
    
    $('.plus_minus_theme').click(function(){                                                        
        var div_id = $(this).attr('id').substr(4);                             
        var img_src = $(this).css('background');                                                        
        $('#'+div_id).toggle(500);
        if (img_src.indexOf('plus') > 0) {                                
            new_img_src = img_src.replace('plus','minus');
            $(this).css('background',new_img_src);
        }
        else {                            
            new_img_src = img_src.replace('minus','plus');
            $(this).css('background',new_img_src);
        }
    });     
})(jQuery);